package org.zizi.dao;

import org.zizi.modal.User;
import org.zizi.util.PagedList;

public class UserDaoImpl extends BaseDao implements UserDao
{
	public void addOrUpdateUser(User user) throws Exception
	{
		User t = esql.helper().queryi(User.class, "t_user", "id=?", user.getId());
		if (t == null)
			esql.helper().inserti(user, "t_user");
		else
			esql.helper().updatei(user, "t_user", t.getId());
	}
	
	public User getUser(long id) throws Exception
	{
		return esql.helper().queryi(User.class, "t_user", "id=?", id);
	}

	public User getUser(String login) throws Exception
	{
		return esql.helper().query(User.class, "t_user", null, null, "login=?", login);
	}
	
	public User getUserByNsrdzdah(String nsrdzdah) throws Exception
	{
		return esql.helper().query(User.class, "t_user", null, null, "nsrdzdah=?", nsrdzdah);
	}
	
	public PagedList<User> searchManagingUser(String key, String relationCode, int offset, int limit) throws Exception
	{
		return esql.helper().page(User.class, "t_user u, t_inland_revenue_org org", offset, limit, "u.*", null, "id", "u.org_code=org.code and org.relation_code like ? and (u.name like ? or u.login like ?)", relationCode + "%", "%" + key + "%", "%" + key + "%");
	}
}
